#ifndef _MSSQLDATATABLE_H_
#define _MSSQLDATATABLE_H_
#include <buildspec.h>
#include <Client/ClientUtils/Network/AbstractDataTable.h>

#include <string>
#include <boost/any.hpp>
#include <boost/ptr_container/ptr_vector.hpp>

namespace GST {
namespace ClientUtils {
	//helpers:
	struct GST_API_EXPORT MSSQLFieldInfo
	{
		TableAttributeDesc::DType dtype;
		std::string name;
		unsigned long dimension;
		bool notNull;

		MSSQLFieldInfo(short _dtype, std::string _name, unsigned long _dim, bool _notNull);
		MSSQLFieldInfo(const MSSQLFieldInfo& other);
		MSSQLFieldInfo& operator=(const MSSQLFieldInfo& other);
	};

class GST_API_EXPORT MSSQLDataTable
		: public AbstractDataTable
{
	void* sqlstatementhandle;
	boost::ptr_vector<MSSQLFieldInfo> columnInfos;
	unsigned int column_count;
	std::vector<void*> row;

public:
	MSSQLDataTable(void* _sqlstatementhandle);
	MSSQLDataTable(const MSSQLDataTable &other);
	virtual MSSQLDataTable &operator=(const MSSQLDataTable &other);
	virtual ~MSSQLDataTable();
	///@name getter
	//@{
	virtual boost::any get(const std::type_info& returntype, int col);
	virtual bool isNull(int col);
	virtual std::string getName(int col) const;
	virtual TableAttributeDesc::DType getType(int col) const;
	virtual int getDimension(int col) const;
	virtual bool isNullable(int col) const;
	virtual unsigned int cols() const;
	virtual bool nextRow();
	//@}
protected:
	virtual AbstractRDBAttributeDesc * newAttributeDesc(const TableAttributeDesc & desc, bool is_primaryKey=false) const;
private:
	void GetErrorMessage(unsigned int handletype, void* handle);
	void freeRowData();
};
}
}
#endif //_MSSQLDATATABLE_H_